﻿using Microsoft.Extensions.Options;

namespace 开发自己的配置提供者;

public class WebConfigController
{
    private readonly IOptionsSnapshot<myWebConfig> _optionsSnapshot;

    public WebConfigController(IOptionsSnapshot<myWebConfig> optionsSnapshot)
    {
        _optionsSnapshot = optionsSnapshot;
    }

    public void PrintValue()
    {
        var myConfig = _optionsSnapshot.Value;
        if (myConfig!=null)
        {
            string connStr = myConfig.connstr1.ConnectionString;
            string providerName = myConfig.connstr1.providerName;
            string server = myConfig.Smtp.Server;
            int port = myConfig.Smtp.Port;
            string pwd = myConfig.Smtp.Pwd;
            Console.WriteLine($"connStr:{connStr}\r\nproviderName:{providerName}\r\nserver:{server}\r\nport:{port}\r\npwd:{pwd}");
        }
    }
}